/**
 * Created by asus on 2017/7/27.
 */
$(function () {
    $.ajax({
        data:'get',
        url:'http://127.0.0.1:3000/api/getcategorytitle',
        dataType:'json',
        success:function (data) {
            console.log(data);
            var html=template("category-template",data);
            $('#category').html(html);


            $('#category>.panel-group>.panel >.panel-heading>.panel-title>a').click(function () {
                var titleId=this.dataset['titleMyId'];
                var targetContainerId=this.href.split('#')[1];
                var targetContainerHtml=$("#category>.panel-group>.panel > #" + targetContainerId + ">.panel-body").html();
                if(targetContainerHtml==""){
                    $.ajax({
                        url:'http://127.0.0.1:3000/api/getcategory',
                        dataType:'json',
                        data:{titleid:titleId},
                        success:function (data) {
                            console.log(data);
                            var childCategoryHtml=template('child-category-template',data);
                            // console.log(childCategoryHtml)
                            $("#category>.panel-group>.panel > #" + targetContainerId + ">.panel-body").html(childCategoryHtml);
                        }
                    })
                }
                // return false;
            })
        }
    })
})